package com.cloud.wms.ui.main.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.List;

/**
 * @Author:Chen
 * @Date: 2021-01-19 16:50
 * @Description:
 */
public class CommodityEntity implements Parcelable {
    protected long commodityId;
    protected String barCode;
    protected String logisticsCode;
    protected String commodityCode;
    protected String commodityName;
    protected int amount;
    protected List<String> commodityCodeList;
    protected int stockType;//良次废
    protected long productBatchID;
    protected String productionDate;
    protected String expirationDate;
    protected String inDate;
    protected String posCode;
    protected long posID;
    protected boolean flag;
    protected long memberID;

    public boolean matchBarCode(String code) {
        if (TextUtils.isEmpty(code)) return false;
        if (code.equalsIgnoreCase(getBarCode())) return true;
        if (code.equalsIgnoreCase(getCommodityCode())) return true;
        if (null == getCommodityCodeList() || getCommodityCodeList().isEmpty()) return false;
        for (int i = 0; i < getCommodityCodeList().size(); i++) {
            if (code.equalsIgnoreCase(getCommodityCodeList().get(i))) return true;
        }
        return false;
    }

    public long getMemberID() {
        return memberID;
    }

    public void setMemberID(long memberID) {
        this.memberID = memberID;
    }

    public String getLogisticsCode() {
        return logisticsCode;
    }

    public void setLogisticsCode(String logisticsCode) {
        this.logisticsCode = logisticsCode;
    }

    public String getCommodityCode() {
        return commodityCode == null ? "" : commodityCode;
    }

    public void setCommodityCode(String commodityCode) {
        this.commodityCode = commodityCode;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getPosCode() {
        return posCode == null ? "" : posCode;
    }

    public void setPosCode(String posCode) {
        this.posCode = posCode;
    }

    public long getPosID() {
        return posID;
    }

    public void setPosID(long posID) {
        this.posID = posID;
    }

    public long getProductBatchID() {
        return productBatchID;
    }

    public void setProductBatchID(long productBatchID) {
        this.productBatchID = productBatchID;
    }

    public String getProductionDate() {
        return productionDate == null ? "" : productionDate.replace("T", " ");
    }

    public void setProductionDate(String productionDate) {
        this.productionDate = productionDate;
    }

    public String getExpirationDate() {
        return expirationDate == null ? "" : expirationDate.replace("T", " ");
    }

    public void setExpirationDate(String expirationDate) {
        this.expirationDate = expirationDate;
    }

    public String getInDate() {
        return inDate == null ? "" : inDate.replace("T", " ");
    }

    public void setInDate(String inDate) {
        this.inDate = inDate;
    }

    public long getCommodityId() {
        return commodityId;
    }

    public void setCommodityId(long commodityID) {
        this.commodityId = commodityID;
    }

    public String getBarCode() {
        return barCode == null ? "" : barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public String getCommodityName() {
        return commodityName == null ? "" : commodityName;
    }

    public void setCommodityName(String commodityName) {
        this.commodityName = commodityName;
    }

    public List<String> getCommodityCodeList() {
        return commodityCodeList;
    }

    public void setCommodityCodeList(List<String> commodityCodeList) {
        this.commodityCodeList = commodityCodeList;
    }

    public boolean isBatch() {
        String batchInfo = inDate + productionDate + expirationDate;
        return !TextUtils.isEmpty(batchInfo);
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public int getStockType() {
        return stockType;
    }

    public String getStockTypeName() {
        switch (stockType){
            case 1:
                return "良品";
            case 2:
                return "次品";
            case 3:
                return "废品";
        }
        return "良品";
    }

    public void setStockType(int stockType) {
        this.stockType = stockType;
    }

    public CommodityEntity() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.commodityId);
        dest.writeString(this.barCode);
        dest.writeString(this.logisticsCode);
        dest.writeString(this.commodityCode);
        dest.writeString(this.commodityName);
        dest.writeInt(this.amount);
        dest.writeStringList(this.commodityCodeList);
        dest.writeInt(this.stockType);
        dest.writeLong(this.productBatchID);
        dest.writeString(this.productionDate);
        dest.writeString(this.expirationDate);
        dest.writeString(this.inDate);
        dest.writeString(this.posCode);
        dest.writeLong(this.posID);
        dest.writeByte(this.flag ? (byte) 1 : (byte) 0);
        dest.writeLong(this.memberID);
    }

    protected CommodityEntity(Parcel in) {
        this.commodityId = in.readLong();
        this.barCode = in.readString();
        this.logisticsCode = in.readString();
        this.commodityCode = in.readString();
        this.commodityName = in.readString();
        this.amount = in.readInt();
        this.commodityCodeList = in.createStringArrayList();
        this.stockType = in.readInt();
        this.productBatchID = in.readLong();
        this.productionDate = in.readString();
        this.expirationDate = in.readString();
        this.inDate = in.readString();
        this.posCode = in.readString();
        this.posID = in.readLong();
        this.flag = in.readByte() != 0;
        this.memberID = in.readLong();
    }

    public static final Creator<CommodityEntity> CREATOR = new Creator<CommodityEntity>() {
        @Override
        public CommodityEntity createFromParcel(Parcel source) {
            return new CommodityEntity(source);
        }

        @Override
        public CommodityEntity[] newArray(int size) {
            return new CommodityEntity[size];
        }
    };
}
